Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class PanelMenuSphereSlider : MonoBehaviour
  6. {
  7. public Slider slider;
  8. public MeshRenderer changeObject;
  9. public VRTK_PanelMenuItemController panelMenuController;
  10. public Color[] colours = new Color[0];
  11. protected virtual void OnEnable()
  12. {
  13. if (panelMenuController != null)
  14. {
  15. panelMenuController.PanelMenuItemSwipeRight += PanelMenuItemSwipeRight;
  16. panelMenuController.PanelMenuItemSwipeLeft += PanelMenuItemSwipeLeft;
  17. }
  18. }
  19. protected virtual void OnDisable()
  20. {
  21. if (panelMenuController != null)
  22. {
  23. panelMenuController.PanelMenuItemSwipeRight -= PanelMenuItemSwipeRight;
  24. panelMenuController.PanelMenuItemSwipeLeft -= PanelMenuItemSwipeLeft;
  25. }
  26. }
  27. protected virtual void PanelMenuItemSwipeRight(object sender, PanelMenuItemControllerEventArgs e)
  28. {
  29. if (slider != null)
  30. {
  31. slider.value++;
  32. SetColor();
  33. }
  34. }
  35. protected virtual void PanelMenuItemSwipeLeft(object sender, PanelMenuItemControllerEventArgs e)
  36. {
  37. if (slider != null)
  38. {
  39. slider.value--;
  40. SetColor();
  41. }
  42. }
  43. protected virtual void SetColor()
  44. {
  45. if (slider.value < colours.Length && changeObject != null)
  46. {
  47. changeObject.material.color = colours[(int)slider.value];
  48. }
  49. }
  50. }
  51. }